#!/usr/bin/env bash


# ----------------------------------------------------------------------
# Filename	:  icmpTime
# Version	:  1.0
# Date		:  2022/01/24
# Author	:  Lz
# Email		:  liuzuo@kylinos.com.cn 
# History	:     
#            	   Version 1.0, 2022/01/24
# Function	:  ICMP时间戳请求
# Out		:        
#              0 => TPASS
#              1 => TFAIL
#              other=> TCONF
# ----------------------------------------------------------------------


# 测试主题
Title_Env_LTFLIB="安全加固(网络类) - ICMP时间戳请求"


## TODO : 个性化,初始化
#   Out : 0=>TPASS
#         1=>TFAIL
#         2=>TCONF
TestInit_LTFLIB(){
	if [ "Z${IcmpTime_Network_SSRFlag}" == "Z" ];then
		OutputRet_LTFLIB "${ERROR}"	
		TestRetParse_LTFLIB "未定义变量 IcmpTime_Network_SSRFlag"
	elif [ "Z${IcmpTime_Network_SSRFlag}" != "ZTrue" -a "Z${IcmpTime_Network_SSRFlag}" != "ZFalse" ];then
		OutputRet_LTFLIB "${ERROR}"	
		TestRetParse_LTFLIB "IcmpTime_Network_SSRFlag 无效的参数: ${IcmpTime_Network_SSRFlag}"
	fi

        return $TPASS
}


## TODO : 清理函数
#   Out : 0=>TPASS
#         1=>TFAIL
#         2=>TCONF
TestClean_LTFLIB(){
        return $TPASS
}


## TODO : 测试用例集
#   Out : 0=>TPASS
#         1=>TFAIL
#         2=>TCONF
Testsuite_LTFLIB(){
        testcase_1

        return $TPASS
}

testcase_1(){
	if [ "Z${IcmpTime_Network_SSRFlag}" == "ZTrue" ];then
		local reverse_flag="yes"	
	else
		local reverse_flag="no"	
	fi

        local flag1="ipv4 filter INPUT 0 -p ICMP --icmp-type timestamp-request -m comment --comment 'deny ICMP timestamp' -j DROP"
        local flag2="ipv4 filter INPUT 0 -p ICMP --icmp-type timestamp-reply -m comment --comment 'deny ICMP timestamp' -j DROP"
        local cmd="sudo firewall-cmd --direct --get-all-rules"

	Info_LLE "$(eval $cmd)"

        eval $cmd | grep -q "$flag1"
	CommRetParse_LTFLIB "'${flag1}':要求 '${IcmpTime_Network_SSRFlag}' (True->不存在，False->存在)" "False" "${reverse_flag}"

        eval $cmd | grep -q "$flag2"
	CommRetParse_LTFLIB "'${flag1}':要求 '${IcmpTime_Network_SSRFlag}' (True->不存在，False->存在)" "False" "${reverse_flag}"
}


#----------------------------------------------#

source "${LIB_LTFLIB}"
Main_LTFLIB $@
